package com.jeecms.wicool.manager.shops.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeecms.cms.entity.main.CmsUser;
import com.jeecms.common.hibernate3.Updater;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.shops.ServiceUserDao;
import com.jeecms.wicool.entity.shops.ServiceUser;
import com.jeecms.wicool.entity.shops.ShopInfo;
import com.jeecms.wicool.manager.shops.ServiceUserMng;
import com.jeecms.wicool.manager.shops.WiShopInfoMng;

@Service
@Transactional
public class ServiceUserMngImpl implements ServiceUserMng {
	
	private ServiceUserDao dao;
	@Autowired
	public void setDao(ServiceUserDao dao) {
		this.dao = dao;
	}
	
	@Transactional(readOnly = true)
	public Pagination getPage(String serviceId,String serviceName,int pageNo, int pageSize,CmsUser user) {
		Pagination page = dao.getPage(serviceId, serviceName, pageNo, pageSize, user);
		return page;
	}
	@Override
	public ServiceUser findById(Integer id) {
		ServiceUser entity = dao.findById(id);
		return entity;
	}
	@Override
	public ServiceUser update(ServiceUser bean,Integer shopId) {
		ShopInfo shop= shopMng.findById(shopId);
		bean.setShop(shop);
		Updater<ServiceUser> updater = new Updater<ServiceUser>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}
	
	@Override
	public ServiceUser save(ServiceUser bean,Integer shopId) {
		
		ShopInfo shop= shopMng.findById(shopId);
		bean.setShop(shop);
		dao.save(bean);
		return bean;
	}

	@Override
	public ServiceUser deleteById(Integer id) {
		ServiceUser bean = dao.deleteById(id);
		return bean;
	}
	@Override
	public ServiceUser[] deleteByIds(Integer[] ids) {
		ServiceUser[] beans = new ServiceUser[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}
	@Override
	public List<ServiceUser> getAll(CmsUser user) {
		// TODO Auto-generated method stub
		return dao.getAll(user);
	}
	@Autowired
	private WiShopInfoMng shopMng;
	
}